package server;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Message {
	private String			command;
	private List<String>	parameters;

	public Message(String message) {
		StringTokenizer tokenizer = new StringTokenizer(message, ":");
		if (tokenizer.countTokens() == 2) {
			setCommand(tokenizer.nextToken());
			setParameters(tokenizer.nextToken());
		} else {
			System.out.println("ERROR - parameters");
		}
	}

	public Message(String command, String result) {
		this.setCommand(command);
		setParameters(result);
	}

	public void setCommand(String command) {
		this.command = command;
	}

	public String getCommand() {
		return command;
	}

	public void setParameters(String parameters) {
		List<String> parameterList = new ArrayList<String>();
		StringTokenizer tok = new StringTokenizer(parameters, ";");
		while (tok.hasMoreElements()) {
			parameterList.add(tok.nextToken());
		}
		this.parameters = parameterList;
	}

	public List<String> getParameters() {
		return parameters;
	}

	public String toString() {
		String string = command + ":";
		for (String i : parameters) {
			if (i.equals(parameters.get(parameters.size() - 1))) {
				string += i;
			} else {
				string += i + ";";
			}
		}
		return string;
	}
}
